<!DOCTYPE html>

<html lang="en">
  <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Class Phalcon\Mvc\Router &mdash; Phalcon 2.0.0 文档</title>
    <meta name="keywords" content="php, phalcon, phalcon php, php framework, faster php framework"><link rel="stylesheet" type="text/css" href="../_static/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="http://static.phalconphp.com/css/phalcon.min.css" />
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:700,400' rel='stylesheet' type='text/css'>
    <link href="http://fonts.googleapis.com/css?family=Merriweather:400,700" rel="stylesheet" type="text/css" />
    <!--
    EUROPE <link href='https://fonts.googleapis.com/css?family=Open+Sans:700,400&subset=latin-ext' rel='stylesheet' type='text/css'>
    GREEK <link href='https://fonts.googleapis.com/css?family=Open+Sans:700,400&subset=greek-ext' rel='stylesheet' type='text/css'>
    RUSSIA <link href='https://fonts.googleapis.com/css?family=Open+Sans:700,400&subset=cyrillic-ext,latin' rel='stylesheet' type='text/css'>
    -->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/docs.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.0.0',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>

    <script src="../_static/jquery.min.js"></script>
    <script type="text/javascript" src="../_static/docs.js"></script>
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
    <link rel="top" title="Phalcon 2.0.0 文档" href="../index.html" />
    <link rel="up" title="API Indice" href="index.html" />
    <link rel="next" title="Class Phalcon\Mvc\Router\Annotations" href="Phalcon_Mvc_Router_Annotations.html" />
    <link rel="prev" title="Class Phalcon\Mvc\Model\Validator\Url" href="Phalcon_Mvc_Model_Validator_Url.html" /> 
  </head>
  <body>

<header class="page-header">
    <nav class="navbar" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu-container">
                    <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                </button>
                <a class="navbar-brand phalcon-logo" href="/"><span itemprop="name" class="sr-only">Phalcon PHP</span></a>
            </div>

            <div class="collapse navbar-collapse navbar-right" id="main-menu-container">
                <ul class="nav navbar-nav main-menu">
                  <li class="first"><a href="http://phalconphp.com/en/download" class="header-nav-link">Download</a></li>
                  <li><a href="http://docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                  <li><a href="http://forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                  <li><a href="http://blog.phalconphp.com/" class="header-nav-link" target="_blank">Blog</a></li>
                  <li><a href="http://phalconphp.com/en/about">About</a></li>
                </ul>
            </div>
        </div>
    </nav>
  </header>

<div class="heading">
    <div class="container">
        <div class="row">
            <h2>Documentation</h2>
        </div>
    </div>
</div>
    <!--<div class="header-line">
      <div class="size-wrap">
        <div class="header-line-title title-white">Documentation</div>
      </div>
    </div>-->
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="Phalcon_Mvc_Router_Annotations.html" title="Class Phalcon\Mvc\Router\Annotations"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="Phalcon_Mvc_Model_Validator_Url.html" title="Class Phalcon\Mvc\Model\Validator\Url"
             accesskey="P">上一页</a> |</li>
        <li><a href="http://phalconphp.com">Home</a> &raquo;</li>
        <li><a href="../index.html">Phalcon 2.0.0 文档</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">API Indice</a> &raquo;</li> 
      </ul>
    </div>  

      <table width="100%" align="center" cellpadding="0" cellspacing="0">
        <tr>
      <td class="primary-box" width="25%" valign="top">
            <div>
            <div id="searchbox" style="">
                <!--<form class="search" action="http://readthedocs.org/search/project/" method="get">
                  <input type="search" name="q" size="25" placeholder="Search">
                  <input type="submit" value="Go">
                  <input type="hidden" name="selected_facets" value="project:">
                </form>-->
                <div style="width:200px;padding:10px">
                  <gcse:searchbox-only></gcse:searchbox-only>
                </div>
            </div>
            </div>
            <div style="padding:5px;padding-left:10px">
              <div id="carbonads-container">
                <div class="carbonad"><div id="azcarbon"></div>
                <script type="text/javascript">var z = document.createElement("script"); z.type = "text/javascript"; z.async = true; z.src = "http://engine.carbonads.com/z/56496/azcarbon_2_1_0_VERT"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(z, s);</script>
                </div></div>
            </div>
            <h3><a href="../index.html">內容目录</a></h3>
            <ul>
<li><a class="reference internal" href="#">Class <strong>Phalcon\Mvc\Router</strong></a><ul>
<li><a class="reference internal" href="#constants">Constants</a></li>
<li><a class="reference internal" href="#methods">Methods</a></li>
</ul>
</li>
</ul>

            <h4>上一个主题</h4>
            <p class="topless"><a href="Phalcon_Mvc_Model_Validator_Url.html" title="上一章">&lt; Class <strong>Phalcon\Mvc\Model\Validator\Url</strong></a></p>
            <h4>下一个主题</h4>
            <p class="topless"><a href="Phalcon_Mvc_Router_Annotations.html" title="下一章">Class <strong>Phalcon\Mvc\Router\Annotations</strong> &gt;</a></p>
            <h3>本页</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/api/Phalcon_Mvc_Router.txt" rel="nofollow">显示源代码</a></li>
            </ul>
        </td>
          <td class="second-box" valign="top">
            <div class="document">
                <div class="documentwrapper">
                  <div class="bodywrapper">
                    <div class="body" >
                      
  <div class="section" id="class-phalcon-mvc-router">
<h1>Class <strong>Phalcon\Mvc\Router</strong><a class="headerlink" href="#class-phalcon-mvc-router" title="永久链接至标题">¶</a></h1>
<p><em>implements</em> <tt class="xref doc docutils literal"><span class="pre">Phalcon\Di\InjectionAwareInterface</span></tt>, <a class="reference internal" href="Phalcon_Mvc_RouterInterface.html"><em>Phalcon\Mvc\RouterInterface</em></a></p>
<p>Phalcon\Mvc\Router is the standard framework router. Routing is the process of taking a URI endpoint (that part of the URI which comes after the base URL) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$router</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Router</span><span class="p">();</span>

<span class="nv">$router</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span>
    <span class="s2">&quot;/documentation/{chapter}/{name}.{type:[a-z]+}&quot;</span><span class="p">,</span>
    <span class="k">array</span><span class="p">(</span>
            <span class="s2">&quot;controller&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;documentation&quot;</span><span class="p">,</span>
            <span class="s2">&quot;action&quot;</span>     <span class="o">=&gt;</span> <span class="s2">&quot;show&quot;</span>
    <span class="p">)</span>
<span class="p">);</span>

<span class="nv">$router</span><span class="o">-&gt;</span><span class="na">handle</span><span class="p">();</span>

<span class="k">echo</span> <span class="nv">$router</span><span class="o">-&gt;</span><span class="na">getControllerName</span><span class="p">();</span>
</pre></div>
</div>
<div class="section" id="constants">
<h2>Constants<a class="headerlink" href="#constants" title="永久链接至标题">¶</a></h2>
<p><em>integer</em> <strong>URI_SOURCE_GET_URL</strong></p>
<p><em>integer</em> <strong>URI_SOURCE_SERVER_REQUEST_URI</strong></p>
</div>
<div class="section" id="methods">
<h2>Methods<a class="headerlink" href="#methods" title="永久链接至标题">¶</a></h2>
<p>public  <strong>__construct</strong> ([<em>unknown</em> $defaultRoutes])</p>
<p>Phalcon\Mvc\Router constructor</p>
<p>public  <strong>setDI</strong> (<em>unknown</em> $dependencyInjector)</p>
<p>Sets the dependency injector</p>
<p>public  <strong>getDI</strong> ()</p>
<p>Returns the internal dependency injector</p>
<p>public  <strong>getRewriteUri</strong> ()</p>
<p>Get rewrite info. This info is read from $_GET[&#8216;_url&#8217;]. This returns &#8216;/&#8217; if the rewrite information cannot be read</p>
<p>public  <strong>setUriSource</strong> (<em>unknown</em> $uriSource)</p>
<p>Sets the URI source. One of the URI_SOURCE_* constants</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="nv">$router</span><span class="o">-&gt;</span><span class="na">setUriSource</span><span class="p">(</span><span class="nx">Router</span><span class="o">::</span><span class="na">URI_SOURCE_SERVER_REQUEST_URI</span><span class="p">);</span>
</pre></div>
</div>
<p>public  <strong>removeExtraSlashes</strong> (<em>unknown</em> $remove)</p>
<p>Set whether router must remove the extra slashes in the handled routes</p>
<p>public  <strong>setDefaultNamespace</strong> (<em>unknown</em> $namespaceName)</p>
<p>Sets the name of the default namespace</p>
<p>public  <strong>setDefaultModule</strong> (<em>unknown</em> $moduleName)</p>
<p>Sets the name of the default module</p>
<p>public  <strong>setDefaultController</strong> (<em>unknown</em> $controllerName)</p>
<p>Sets the default controller name</p>
<p>public  <strong>setDefaultAction</strong> (<em>unknown</em> $actionName)</p>
<p>Sets the default action name</p>
<p>public  <strong>setDefaults</strong> (<em>unknown</em> $defaults)</p>
<p>Sets an array of default paths. If a route is missing a path the router will use the defined here This method must not be used to set a 404 route</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

 <span class="nv">$router</span><span class="o">-&gt;</span><span class="na">setDefaults</span><span class="p">(</span><span class="k">array</span><span class="p">(</span>
    <span class="s1">&#39;module&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;common&#39;</span><span class="p">,</span>
    <span class="s1">&#39;action&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;index&#39;</span>
 <span class="p">));</span>
</pre></div>
</div>
<p>public  <strong>handle</strong> ([<em>unknown</em> $uri])</p>
<p>Handles routing information received from the rewrite engine</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

 <span class="c1">//Read the info from the rewrite engine</span>
 <span class="nv">$router</span><span class="o">-&gt;</span><span class="na">handle</span><span class="p">();</span>

 <span class="c1">//Manually passing an URL</span>
 <span class="nv">$router</span><span class="o">-&gt;</span><span class="na">handle</span><span class="p">(</span><span class="s1">&#39;/posts/edit/1&#39;</span><span class="p">);</span>
</pre></div>
</div>
<p>public <a class="reference internal" href="Phalcon_Mvc_Router_Route.html"><em>Phalcon\Mvc\Router\Route</em></a>  <strong>add</strong> (<em>unknown</em> $pattern, [<em>unknown</em> $paths], [<em>unknown</em> $httpMethods])</p>
<p>Adds a route to the router without any HTTP constraint</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

 <span class="nv">$router</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span><span class="s1">&#39;/about&#39;</span><span class="p">,</span> <span class="s1">&#39;About::index&#39;</span><span class="p">);</span>
</pre></div>
</div>
<p>public  <strong>addGet</strong> (<em>unknown</em> $pattern, [<em>unknown</em> $paths])</p>
<p>Adds a route to the router that only match if the HTTP method is GET</p>
<p>public  <strong>addPost</strong> (<em>unknown</em> $pattern, [<em>unknown</em> $paths])</p>
<p>Adds a route to the router that only match if the HTTP method is POST</p>
<p>public  <strong>addPut</strong> (<em>unknown</em> $pattern, [<em>unknown</em> $paths])</p>
<p>Adds a route to the router that only match if the HTTP method is PUT</p>
<p>public <a class="reference internal" href="Phalcon_Mvc_Router_Route.html"><em>Phalcon\Mvc\Router\Route</em></a>  <strong>addPatch</strong> (<em>unknown</em> $pattern, [<em>unknown</em> $paths])</p>
<p>Adds a route to the router that only match if the HTTP method is PATCH</p>
<p>public <a class="reference internal" href="Phalcon_Mvc_Router_Route.html"><em>Phalcon\Mvc\Router\Route</em></a>  <strong>addDelete</strong> (<em>unknown</em> $pattern, [<em>unknown</em> $paths])</p>
<p>Adds a route to the router that only match if the HTTP method is DELETE</p>
<p>public <a class="reference internal" href="Phalcon_Mvc_Router_Route.html"><em>Phalcon\Mvc\Router\Route</em></a>  <strong>addOptions</strong> (<em>unknown</em> $pattern, [<em>unknown</em> $paths])</p>
<p>Add a route to the router that only match if the HTTP method is OPTIONS</p>
<p>public <a class="reference internal" href="Phalcon_Mvc_Router_Route.html"><em>Phalcon\Mvc\Router\Route</em></a>  <strong>addHead</strong> (<em>unknown</em> $pattern, [<em>unknown</em> $paths])</p>
<p>Adds a route to the router that only match if the HTTP method is HEAD</p>
<p>public <a class="reference internal" href=""><em>Phalcon\Mvc\Router</em></a>  <strong>mount</strong> (<em>unknown</em> $group)</p>
<p>Mounts a group of routes in the router</p>
<p>public  <strong>notFound</strong> (<em>unknown</em> $paths)</p>
<p>Set a group of paths to be returned when none of the defined routes are matched</p>
<p>public  <strong>clear</strong> ()</p>
<p>Removes all the pre-defined routes</p>
<p>public  <strong>getNamespaceName</strong> ()</p>
<p>Returns the processed namespace name</p>
<p>public  <strong>getModuleName</strong> ()</p>
<p>Returns the processed module name</p>
<p>public  <strong>getControllerName</strong> ()</p>
<p>Returns the processed controller name</p>
<p>public  <strong>getActionName</strong> ()</p>
<p>Returns the processed action name</p>
<p>public  <strong>getParams</strong> ()</p>
<p>Returns the processed parameters</p>
<p>public  <strong>getMatchedRoute</strong> ()</p>
<p>Returns the route that matchs the handled URI</p>
<p>public  <strong>getMatches</strong> ()</p>
<p>Returns the sub expressions in the regular expression matched</p>
<p>public  <strong>wasMatched</strong> ()</p>
<p>Checks if the router macthes any of the defined routes</p>
<p>public <a class="reference internal" href="Phalcon_Mvc_Router_Route.html"><em>Phalcon\Mvc\Router\Route</em></a> [] <strong>getRoutes</strong> ()</p>
<p>Returns all the routes defined in the router</p>
<p>public  <strong>getRouteById</strong> (<em>unknown</em> $id)</p>
<p>Returns a route object by its id</p>
<p>public  <strong>getRouteByName</strong> (<em>unknown</em> $name)</p>
<p>Returns a route object by its name</p>
<p>public  <strong>isExactControllerName</strong> ()</p>
<p>Returns whether controller name should not be mangled</p>
</div>
</div>


                    </div>
                  </div>
                </div>
            </div>
          </td>
        </tr>
      </table>
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="Phalcon_Mvc_Router_Annotations.html" title="Class Phalcon\Mvc\Router\Annotations"
             >下一页</a> |</li>
        <li class="right" >
          <a href="Phalcon_Mvc_Model_Validator_Url.html" title="Class Phalcon\Mvc\Model\Validator\Url"
             >上一页</a> |</li>
          <li class="right"><a href="index.html" >API Indice</a> &raquo;</li> 
      </ul>
    </div>

      <div class="prefooter">
  <div class="container">
      <div class="row">
          <div class="col-sm-3 text-right">
              <span>Follow along:</span>
          </div>
          <div class="col-sm-6 text-center">
              <a href="https://twitter.com/phalconphp" alt="Twitter" class="btn-social btn-social-twitter"><i class="icon-twitter"></i></a>
              <a href="https://www.facebook.com/pages/Phalcon-Framework/134230726685897" alt="Facebook" class="btn-social btn-social-facebook"><i class="icon-facebook"></i></a>
              <a href="https://plus.google.com/102376109340560896457" alt="Google+" class="btn-social btn-social-googleplus"><i class="icon-googleplus"></i></a>
              <a href="https://github.com/phalcon/cphalcon" alt="Github" class="btn-social btn-social-github"><i class="icon-github"></i></a>
          </div>
          <div class="col-sm-3">
          </div>
      </div>
  </div>

</div>
<footer class="footer">
  <div class="container">
      <div class="row">
          <div class="col-xs-4 col-sm-3">
              <h4>Download</h4>
              <ul>
                  <li><a href="http://phalconphp.com/download">Installing Phalcon</a></li>
                  <li><a href="http://docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                  <li><a href="http://api.phalconphp.com">API</a></li>
                  <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html">Tutorial</a></li>
                  <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html#sample-applications">Sample Applications</a></li>
              </ul>
          </div>
          <div class="col-xs-4 col-sm-3">
              <h4>Community</h4>
              <ul>
                  <li><a href="http://forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                  <li><a href="https://github.com/phalcon/cphalcon">GitHub</a></li>
                  <li><a href="https://github.com/phalcon/cphalcon/issues">Issue Tracker</a></li>
                  <li><a href="http://stackoverflow.com/questions/tagged/phalcon">Stack Overflow</a></li>
                  <li><a href="http://phalconphp.com/en/testimonials">Testimonials</a></li>
                  <li><a href="http://builtwith.phalconphp.com/">Built with Phalcon</a></li>
                  <li><a href="http://store.phalconphp.com/">Store</a></li>
              </ul>
          </div>
          <div class="col-xs-4 col-sm-2">
              <h4>About</h4>
              <ul>
                  <li><a class="link-black" href="http://blog.phalconphp.com/">Blog</a></li>
                  <li><a href="http://phalconphp.com/en/about">About</a></li>
                  <li><a href="http://phalconphp.com/en/team">Team</a></li>
                  <li><a href="http://phalconphp.com/en/roadmap">Roadmap</a></li>
                  <li><a href="http://phalconphp.com/en/donate">Donate</a></li>
                  <li><a href="http://phalconphp.com/en/consulting">Consulting</a></li>
                  <li><a href="http://phalconphp.com/en/hosting">Hosting</a></li>
              </ul>
          </div>
          <div id="license-spaccer" class="visible-xs"></div>
          <div id="license-wrapper" class="col-xs-12 col-sm-4">
              <p class="license">

                  Found a typo or an error? Want to improve this document? The documentation sources are available on <a href="http://github.com/phalcon/docs">Github</a><br>
                  Need support or have questions? Check our <a href="http://forum.phalconphp.com">Forum</a><br>
                  <br>

                  Phalcon Framework is released under the <a href="https://github.com/phalcon/cphalcon/blob/master/docs/LICENSE.md">new BSD license</a>.<br>
                  Except where otherwise noted, content on this site is licensed under the
                    <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License.</a>

                <div class="design">
                  <span>Designed by:</span>

                  <a href="http://www.fog-city.net/" class="fogcity" target="_blank" title="Fog City Software"><span>Fog City Software</span></a>
              </div>
          </div>
      </div>
  </div>
</footer>

    </div>
    <script type="text/javascript">
    $(window).on("load", function(){
      var cx = '009733439235723428699:lh9ltjgvdz8';
      var gcse = document.createElement('script');
      gcse.type = 'text/javascript';
      gcse.async = true;
      gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx;
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(gcse, s);
    });
    </script>

  </body>
</html>